/**************************************************************
 * * Copyright (c) 2019-2020 Huawei Technologies Co., Ltd.
 *
 * * License under BSD 3-Clause "New" or "Revised" License
 *
 **************************************************************/
#include <limits.h>
#include "erasure_code.h"

#if __aarch64__
void ec_encode_data_neon(int len, int k, int rows, unsigned char *g_tbls, unsigned char **data, unsigned char **coding)
{
	if (len < 16) {
		ec_encode_data_base(len, k, rows, g_tbls, data, coding);
		return;
	}

	while (rows > 5) {
		gf_5vect_dot_prod_neon(len, k, g_tbls, data, coding);
		g_tbls += 5 * k * 32;
		coding += 5;
		rows -= 5;
	}
	switch (rows) {
	case 5:
		gf_5vect_dot_prod_neon(len, k, g_tbls, data, coding);
		break;
	case 4:
		gf_4vect_dot_prod_neon(len, k, g_tbls, data, coding);
		break;
	case 3:
		gf_3vect_dot_prod_neon(len, k, g_tbls, data, coding);
		break;
	case 2:
		gf_2vect_dot_prod_neon(len, k, g_tbls, data, coding);
		break;
	case 1:
		gf_vect_dot_prod_neon(len, k, g_tbls, data, *coding);
		break;
	case 0:
		break;
	default:
		break;
	}
}

void ec_encode_data_update_neon(int len, int k, int rows, int vec_i, unsigned char *g_tbls,
			       unsigned char *data, unsigned char **coding)
{
	if (len < 16) {
		ec_encode_data_update_base(len, k, rows, vec_i, g_tbls, data, coding);
		return;
	}
	while (rows > 6) {
		gf_6vect_mad_neon(len, k, vec_i, g_tbls, data, coding);
		g_tbls += 6 * k * 32;
		coding += 6;
		rows -= 6;
	}
	switch (rows) {
	case 6:
		gf_6vect_mad_neon(len, k, vec_i, g_tbls, data, coding);
		break;
	case 5:
		gf_5vect_mad_neon(len, k, vec_i, g_tbls, data, coding);
		break;
	case 4:
		gf_4vect_mad_neon(len, k, vec_i, g_tbls, data, coding);
		break;
	case 3:
		gf_3vect_mad_neon(len, k, vec_i, g_tbls, data, coding);
		break;
	case 2:
		gf_2vect_mad_neon(len, k, vec_i, g_tbls, data, coding);
		break;
	case 1:
		gf_vect_mad_neon(len, k, vec_i, g_tbls, data, *coding);
		break;
	case 0:
		break;
	}
	return;
}
#endif
